<template>
  <header class="header">
    <h1>todos</h1>
    <input
      class="new-todo"
      placeholder="请输入任务名称"
      autofocus
      v-model.trim="name"
      @keyup.enter="handleAdd"
    />
  </header>
</template>

<script>
export default {
  data() {
    return {
      name: "",
    };
  },
  methods: {
    handleAdd() {
      //   console.log(this.name);
      // 校验
      if (!this.name) {
        alert("填写内容不能为空");
        return;
      }
      this.$emit("add", this.name);
      // 清空
      this.name = "";
    },
  },
};
</script>

<style>
</style>